﻿namespace Digitalmes.Domain.Mes;

/// <summary>
/// 工序 BOM
/// </summary>
[SugarTable("proc_bom", "工序BOM表")]
public class ProcBom : EntityBase
{
    /// <summary>
    /// 产品 Id
    /// </summary>
    [SugarColumn(ColumnDescription = "产品Id")]
    public long ProductId { get; set; }

    /// <summary>
    /// 产品（成品）信息
    /// </summary>
    [Navigate(NavigateType.OneToOne, nameof(ProductId))]
    public MdItem? Product { get; set; }

    /// <summary>
    /// 工艺路线Id
    /// </summary>
    [SugarColumn(ColumnDescription = "工艺路线Id")]
    public long RoutingId { get; set; }

    [Navigate(NavigateType.OneToOne, nameof(RoutingId))]
    public ProcRouting? Routing { get; set; }

    /// <summary>
    /// 工序 Id
    /// </summary>
    [SugarColumn(ColumnDescription = "工序Id")]
    public long ProcessId { get; set; }

    /// <summary>
    /// 工序
    /// </summary>
    [Navigate(NavigateType.OneToOne, nameof(ProcessId))]
    public ProcProcess? Process { get; set; }

    /// <summary>
    /// 物料Id
    /// </summary>
    [SugarColumn(ColumnDescription = "物料Id")]
    public long MaterialId { get; set; }

    /// <summary>
    /// 物料代码
    /// </summary>
    [NotNull]
    [SugarColumn(ColumnDescription = "物料代码", Length = 64)]
    public string? MaterialCode { get; set; }

    /// <summary>
    /// 物料信息
    /// </summary>
    [Navigate(NavigateType.OneToOne, nameof(MaterialId))]
    public MdItem? Material { get; set; }

    /// <summary>
    /// 父BOM Id，0 表示是根节点。
    /// </summary>
    [SugarColumn(ColumnDescription = "父BOM Id")]
    public long ParentId { get; set; }

    /// <summary>
    /// 工艺 BOM 版本
    /// </summary>
    [SugarColumn(ColumnDescription = "工序BOM版本")]
    public int Version { get; set; }

    /// <summary>
    /// 需求数量。
    /// </summary>
    [SugarColumn(ColumnDescription = "需求数量")]
    public int Qty { get; set; } = 1;

    /// <summary>
    /// 上料顺序。
    /// </summary>
    /// <remarks>用在有顺序的扫码上料流程中校验，当数值大于 0 时有效。</remarks>
    [SugarColumn(ColumnDescription = "上料顺序")]
    public int Pos { get; set; }

    /// <summary>
    /// 物料来源工位 Id。
    /// </summary>
    /// <remarks>若设置，表示在该物料是经过设置的工位加工或检验的，可以在上料时做校验物料在来源工位作业结果。</remarks>
    [SugarColumn(ColumnDescription = "物料来源工位 Id")]
    public long? SourceOpId { get; set; }

    /// <summary>
    /// 物料来源工位编号。
    /// </summary>
    [SugarColumn(ColumnDescription = "物料来源工位编号", Length = 32)]
    public string? SourceRawOpCode { get; set; }

    /// <summary>
    /// 物料来源工位。
    /// </summary>
    [Navigate(NavigateType.OneToOne, nameof(SourceOpId))]
    public MdStation? SourceOp { get; set; }
}
